home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 743 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solon.com (Peter Seebach)
  3. Newsgroups: comp.std.c,comp.lang.c.moderated
  4. Subject: Re: printf() format extensions - looking for beta testers...
  5. Date: 14 Apr 1996 23:44:18 -0500
  6. Organization: Usenet Fact Police (Undercover)
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4ksk72$rm6@solutions.solon.com>
  10. References: <4kll9l$o5h@solutions.solon.com> <4kobun$8i2@solutions.solon.com> <4koecq$8up@solutions.solon.com> <4kr74a$k8o@solutions.solon.com>
  11. Reply-To: seebs@solon.com
  12. NNTP-Posting-Host: solutions.solon.com
  13.  
  14. In article <4kr74a$k8o@solutions.solon.com>,
  15. Sean 'Captain Napalm' Conner <spc@gate.net> wrote:
  16. >>%# would be a poor choice; the conversion func for %# is one which returns
  17. >>a magic cookie to set the alternate format flag.  :)
  18.  
  19. >  Oh.  Ah.  Well.  What IS available?
  20.  
  21. Whatever you want; it's just that if you change %#, you change the behavior
  22. of existing legal programs.
  23.  
  24. >  Well, why not change the approach?  The current printf() will accept a
  25. >line such as:
  26.  
  27. >        printf("%*s",someint,somestring);
  28.  
  29. >  To allow variable widths to be specified.  Why not extend that and pass in
  30. >the function pointers?  Something like:
  31.  
  32. >        printf("%p@",myfunctptr,myptrtype);
  33.  
  34. >  Where '@' specifies a format function, and the letter before it declares
  35. >the type using a single letter specification:
  36.  
  37. >        c    - char
  38. >        s    - short
  39. >        i    - int
  40. >        l    - long
  41. >        f    - float
  42. >        d    - double
  43.  
  44. >  With the following modifiers:
  45.  
  46. >        p    - pointer (if alone, void *)
  47. >        u    - unsigned
  48.  
  49. >  Less chance of clashes, and more flexible I feel.
  50.  
  51. Well, that would break existing code, of course; you can actually
  52. do something similar;
  53.     int funcconv(va_list *ap, char *into, int len, fmtspec *fs) {
  54.         fmtconv fc;
  55.  
  56.         fc = va_arg(*ap, fmtconv);
  57.         return fc(ap, into, len, fs);
  58.     }
  59.  
  60. And just bind this to whatever character you want.  (In my sample
  61. implementation, it's %<.)
  62.  
  63. -s
  64. -- 
  65. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  66. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  67. FUCK the communications decency act.  Goddamned government.  [literally.]
  68. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  69.